/*
 * HTThread.cpp
 *
 *  Created on: Mar 16, 2009
 *      Author: Andrzej Olchawa
 *      mailto: andrzejolchawa@gmail.com
 *      http://www.hardtechnology.org
 *      This is a part of the Armazd project, which is covered by
 *      GNU GPL v2 license.
 */

#include "HTThread.h"

template <class T>
HTThread<T>::HTThread()
{
	interrupt = true;
	threadHandle = -1;
}

template <class T>
HTThread<T>::HTThread(bool autoStart)
{
	HTThread();
	if (autoStart)
	{
		start();
	}
}

template <class T>
HTThread<T>::~HTThread() {}

template <class T>
void HTThread<T>::run() {}

template <class T>
void HTThread<T>::setInterrupt(bool value)
{
	interrupt = value;
}

template <class T>
void HTThread<T>::pause()
{
	interrupt = true;
}

template <class T>
void HTThread<T>::start()
{
	interrupt = false;

	if (threadHandle < 0)
	{
		threadHandle = pthread_create(&threadId,NULL,&startRunFunc,(void*)this);
	}
}

template <class T>
void *HTThread<T>::startRunFunc(void *t)
{
	((T*)t)->run();

	return NULL;
}
